<template>
  <div>
      <div class="main-body">
          <div class="main">
              <div class="menu">
                  <div class="m-top">
                      <div class="user-avatar">
                          <img src="@/assets/user.png" alt="Lin">
                      </div>
                      <div class="item">
                          <i class="iconfont icon-xiaoxi"></i>
                      </div>
                      <div class="item">
                          <i class="iconfont icon-lianxiren"></i>
                      </div>
                  </div>
                  <div class="m-bottom">
                      <div class="item">
                          <i class="iconfont icon-caidan"></i>
                      </div>
                      <div class="item">
                          <i class="iconfont icon-icon1"></i>
                      </div>
                  </div>
              </div>
              <div class="list">
                  <div class="search-parent">
                      <div class="search-box">
                          <div ref="searchText" class="text">
                              <i class="iconfont icon-sousuo"></i>
                              搜索
                          </div>
                          <input v-model="search" type="text" @focus="onFocus" @blur="onBlur" class="search">
                      </div>
                  </div>
                  <div class="chat-list">
                      <div class="chat-item active">
                          <div class="avatar">
                              <img src="@/assets/avatar.png" alt="">
                          </div>
                          <div class="content">
                              <div class="name">焦糖板栗-栗子</div>
                              <div class="preview">栗子明白啦~</div>
                          </div>
                      </div>
                      <div class="chat-item" v-for="i in 16" :key="i">
                          <div class="avatar">
                              <img src="@/assets/avatar.png" :alt="i">
                          </div>
                          <div class="content">
                              <div class="name">焦糖板栗-奈栗</div>
                              <div class="preview">你说什么？</div>
                          </div>
                      </div>
                  </div>
              </div>
              <div class="chat">
                  <div class="chat-name">焦糖板栗-栗子</div>
                  <div class="chat-body">
                      <div class="time">16:56</div>
                      <div class="opposite">
                          <div class="avatar">
                              <img src="@/assets/avatar.png" alt=""/>
                          </div>
                          <div class="message">你好，我是新来的前端，以后请多关照！</div>
                      </div>
                      <div class="self">
                          <div class="avatar">
                              <img src="@/assets/avatar.png" alt=""/>
                          </div>
                          <div class="message">你好你好，关照谈不上，大家相互学习</div>
                      </div>
                      <div class="opposite">
                          <div class="avatar">
                              <img src="@/assets/user.png" alt=""/>
                          </div>
                          <div class="message">这是一段测试文本，长度会比较长，目的是为了测试该元素内的文本过长之后换行的样式</div>
                      </div>
                  </div>
                  <div class="chat-box">
                      <div class="chat-tool">
                          <div class="tool-item"></div>
                          <div class="tool-item"></div>
                          <div class="tool-item"></div>
                      </div>
                      <div class="chat-input">
                          <textarea v-model="message" />
                      </div>
                      <div class="send">
                          <div class="send-button">发送</div>
                      </div>
                  </div>
              </div>
          </div>
      </div>
  </div>
</template>

<script>
export default {
    name: 'ChatMain',
    props: {
        msg: String
    },
    data(){
        return{
            search: '',
            message: ''
        }
    },
    methods:{
        onFocus(){
            this.$refs.searchText.classList.add('on-focus')
        },
        onBlur(){
            this.search = ''
            this.$refs.searchText.classList.remove('on-focus')
        }
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
    .main-body{
        width: 100vw;
        height: 100vh;
        background: url("@/assets/bg.jpg") no-repeat;
        background-size: cover;
        overflow: hidden;
        .main{
            width: 50%;
            margin: 20vh auto;
            height: 60vh;
            overflow: hidden;
            border-radius: 0 5px 5px 5px;
            display: flex;
            .menu{
                width: 8%;
                min-width: 58px;
                background: #303a42;
                display: flex;
                flex-direction: column;
                .m-top{
                    padding: 20px 10px 0 10px;
                    height: 50%;
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    color: #fff;
                    .user-avatar{
                        width: 50px;
                        height: 50px;
                        border-radius: 50%;
                        overflow: hidden;
                        margin-bottom: 20px;
                        img{
                            width: 100%;
                        }
                    }
                    div{
                        width: 100%;
                        height: 50px;
                        i{
                            cursor: pointer;
                            font-size: 30px;
                            line-height: 50px;
                        }
                    }
                }
                .m-bottom{
                    height: 50%;
                    display: flex;
                    flex-direction: column-reverse;
                    div{
                        width: 100%;
                        height: 50px;
                        color: #fff;
                        i{
                            cursor: pointer;
                            font-size: 30px;
                            line-height: 50px;
                        }
                    }
                }
            }
        }
    }

    .list{
        width: 26%;
        background: #364048;
        min-width: 166px;
        .search-parent{
            padding: 10px;
        }
        .search-box {
            width: 100%;
            border-radius: 16px;
            height: 32px;
            line-height: 32px;
            background: #454f57;
            position: relative;
            color: #6e787f;
        }
        .text{
            position: absolute;
            z-index: 6;
            left: 26%;
            top: 0;
        }
        .on-focus{
            display: none;
            transition-duration: 600ms;
        }
        .search{
            position: absolute;
            z-index: 9;
            left: 0;
            top: 0;
            border: none;
            width: 100%;
            border-radius: 16px;
            height: 32px;
            line-height: 32;
            outline: none;
            color: #6e787f;
            text-align: center;
            font-size: 16px;
            background: rgba(255,255,255,0);
        }
    }

    .chat-list{
        overflow-y: hidden;
        height: 100%;
        &:hover{
            overflow-y: auto;
            scrollbar-width: thin;
            scrollbar-color: #ccc #fff;
        }

        /* 滚动条栏 */
        &:hover::-webkit-scrollbar {
            width: 6px;
        }

        /* 滚动条thumb */
        &:hover::-webkit-scrollbar-thumb {
            background: rgba(255,255,255,.4);
            border-radius: 2px;
        }
        .chat-item{
            cursor: pointer;
            display: flex;
            height: 40px;
            padding: 10px;
            &:hover{
                background: #3d464d;
            }
            .avatar{
                height: 40px;
                width: 40px;
                img{
                    width: 100%;
                    height: 100%;
                    border-radius: 50%;
                }
            }
            .content{
                text-align: left;
                padding-left: 8px;
                color: #edf4f7;
                font-size: 13px;
                margin-top: 3px;
                .preview{
                    margin-top: 3px;
                    font-size: 12px;
                    color: #8b9399;
                }
            }
        }
        .active{
            background: #3c464e;
        }
    }

    .chat{
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        background: #ffffff;
        width: 100%;
        text-align: left;
        .chat-name{
            height: 46px;
            line-height: 46px;
            padding-left: 10px;
            border-bottom: solid #e8e8e8 1px;
        }
        .time{
            padding: 10px;
            text-align: center;
            font-size: 13px;
            color: #888;
        }
        .chat-body{
            height: 100%;
            display: flex;
            flex-direction: column;
        }
        /*不会被编译，因此也没有作用域*/
        /*该注释会被编译到css中*/
        //该注释不会被编译
        %message-parent{
            display: flex;
            max-width: 66%;
            line-height: 23px;
            margin-bottom: 10px;
            align-self: flex-start;
        }
        %message-avatar{
            align-items: center;
            width: 40px;
            height: 40px;
            padding: 6px;
            img{
                border-radius: 50%;
                height: 100%;
            }
        }
        %message{
            background-color: #e7f3ff;
            border-radius: 10px;
            padding: 10px;
            margin-left: 10px;
            position: relative;
        }
        %message-before{
            content: "";
            position: absolute;
            width: 0;
            height: 0;
            top: 28%;
            border: 8px solid;
            border-color: transparent #e7f3ff transparent transparent;
        }
        .opposite{
            @extend %message-parent;
            .avatar{
                @extend %message-avatar;
            }
            .message{
                @extend %message;
                &:before {
                    left: -15px;
                    @extend %message-before;
                }
            }
        }
        .self{
            @extend %message-parent;
            align-self: flex-end;
            display: flex;
            flex-direction: row-reverse;
            .avatar{
                @extend %message-avatar;
            }
            .message{
                @extend %message;
                background-color: #d2f5e3;
                margin-right: 10px;
                &:before {
                    @extend %message-before;
                    right: -15px;
                    border-color: transparent transparent transparent #d2f5e3;
                }
            }
        }
    }

    .chat-box{
        height: 176px;
        border-top: 1px solid #e8e8e8;
        .chat-input{
            padding: 10px;
            textarea{
                color: #6e787f;
                resize: none;
                height: 100px;
                width: 100%;
                white-space: pre-line;
                border: none;
                outline: none;
                word-wrap: break-word; // 超出长度允许在单词内换行
                word-break: break-all; // 超过长度自动换行
            }
        }
        .send{
            height: 60px;
            display: flex;
            justify-content: flex-end;
            align-items: center;
            padding-right: 10px;
            .send-button{
                cursor: pointer;
                font-size: 13px;
                text-align: center;
                width: 86px;
                height: 26px;
                line-height: 26px;
                color: #ffffff;
                border-radius: 2px;
                justify-content: flex-end;
                background: #31a8dd;
            }
        }
    }
</style>
